package com.atguigu.srb.easyexcel.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.atguigu.srb.easyexcel.pojo.ExcelStudentDTO;

import java.util.ArrayList;
import java.util.List;

public class ExcelStudentListener extends AnalysisEventListener<ExcelStudentDTO> {

    List<ExcelStudentDTO> ExcelStudentDTOCar = new ArrayList<>();

    private static Long count = 0L;

    @Override
    public void invoke(ExcelStudentDTO excelStudentDTO, AnalysisContext analysisContext) {
        ExcelStudentDTOCar.add(excelStudentDTO);
        if (ExcelStudentDTOCar.size()>= 10){
            System.out.println("每读取十行数据，插入"+ ++count +"次");
            System.out.println(ExcelStudentDTOCar);
            System.out.println("数据库写入操作");
            ExcelStudentDTOCar.clear();
        }

    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        System.out.println("断后，兄弟们先走，我断后");
        System.out.println(ExcelStudentDTOCar);
    }
}
